﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace JMT.Data
{
    public class JClass : IJModel, IJContainer<JProperty>, IJContainer<JMethod>
    {
        JContainer<JProperty> _jPropertyContainer;
        JContainer<JMethod> _jMethodContainer;

        public IJContainer<JClass> Container { get; internal set; }

        public JClass()
            : base(JConstString.TClass)
        {
            _jPropertyContainer = new JContainer<JProperty>();
            _jMethodContainer = new JContainer<JMethod>();
        }

        #region property container
        public void Add(JProperty jModel)
        {
            _jPropertyContainer.Add(jModel);
            jModel.Container = this;
        }

        public void Remove(JProperty jModel)
        {
            jModel.Container = null;
            _jPropertyContainer.Remove(jModel);
        }

        public JProperty Get(Guid id)
        {
            return _jPropertyContainer.Get(id);
        }

        public List<JProperty> ToList()
        {
            return _jPropertyContainer.ToList();
        }

        public void Register(JContainerUpdate<JProperty> update)
        {
            _jPropertyContainer.Register(update);
        }
        #endregion

        #region method container
        public void Add(JMethod jModel)
        {
            _jMethodContainer.Add(jModel);
            jModel.Container = this;
        }

        public void Remove(JMethod jModel)
        {
            jModel.Container = null;
            _jMethodContainer.Remove(jModel);
        }

        JMethod IJContainer<JMethod>.Get(Guid id)
        {
            return _jMethodContainer.Get(id);
        }

        List<JMethod> IJContainer<JMethod>.ToList()
        {
            return _jMethodContainer.ToList();
        }

        public void Register(JContainerUpdate<JMethod> update)
        {
            _jMethodContainer.Register(update);
        }
        #endregion
    }
}
